package com.xncoding.design.observation.demo;
/**
 * 消费者
 * @author Administrator
 */
public class Consumer extends Thread {

	private String name;
	private Storage s=null;
	
	
	public Consumer(String name,Storage s){
		this.name=name;
		this.s=s;
	
	}
	@Override
	public void run() {
		try{
			while(true){
				if(s.getWorkQueue().isEmpty()&&s.isEmpty()){//工作完成
	    			break;
	    		}
				Product product=s.pop();
				if(product==null){
					continue;
				}
				System.out.println(name+"已消费（"+product.toString()+").");
			}
		}catch(InterruptedException e){
			System.out.println(name+":异常");
			
		}finally{
			System.out.println(name+":完成工作");
		}
		
	}
	


}
